package Day21.Stream;

import java.util.*;
import java.util.stream.Stream;

/**
 * @version 1.0
 * @BelongsProject:IntelliJ IDEA
 * @BelongsPackage:Day21.Stream
 * @Author:hyhWTX
 * @ClassName:Demo03GetStream
 * @CreateTime:2022年-10月-13日 16:34
 * @Description: TODO (一句话描述以下该类的功能)
 */
/*
    java.util.Stream.Stream<T>是Java 8新加入的最常用的流接口。(这并不是一个函数式接口。)
    获取一个流非常简单,有以下几种常用的方式:
    -所有的Collection集合都可以通过Stream到t认方法获取流:
      default Stream<E> stream ()
    - Stream接口的静态方法of可以获取数组对应的流
      static <T> Stream<T> of (T... values)
    参数是一个可变参数,那么我们就可以传递一个数组

 */
public class Demo03GetStream {
    public static void main(String[] args) {
        //将集合转换为Stream流
        List<String> list = new ArrayList<>();
        Stream<String> stream1 = list.stream();

        Set<String> set = new HashSet<>();
        Stream<String> stream2 = set.stream();
        Map<String, String> map = new HashMap<>();
        //获取键
        Set<String> keySet = map.keySet();
        Stream<String> stream3 = keySet.stream();
        //获取值
        Collection<String> values = map.values();
        Stream<String> stream4 = values.stream();
        //获取键值对,键与值的映射关系
        Set<Map.Entry<String, String>> entries = map.entrySet();
        Stream<Map.Entry<String, String>> stream5 = entries.stream();

        //将数组转换成Stream值
        Stream<Integer> stream6 = Stream.of(1, 2, 3, 4, 5);
        //可变参数可以传递数组
        Integer[] arr = {1,2,3,4};
        Stream<Integer> stream7 = Stream.of(arr);

        String[] arr2 = {"a","b","c"};
        Stream<String> stream8 = Stream.of(arr2);


    }
}
